package com.api.gbhg.zengping.dao;

import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

import java.util.Map;

/**
 * @program: gbhg-oa
 * @author: Mr.zeng
 * @create: 2021-01-14 09:48
 **/
public class BudgeSourceDao {



    /**
     * 预算来源金额扣减
     * @param param
     * @return
     */
    public boolean modifyBudgeSource(Map<String,Object> param){
        RecordSetTrans rst=new RecordSetTrans();
        rst.setAutoCommit(false);
        String modifySql="update uf_jingfeilaiyuan set syed=syed-? where ysly=? and requestId=?";
        try {
            rst.executeUpdate(modifySql,
                    param.get("deduction"),
                    param.get("ysly"),
                    param.get("requestId"));
            // 查询语句 余额不足回滚
            String querySql="SELECT syed FROM uf_jingfeilaiyuan  WHERE ysly=? AND requestId=?";
            rst.executeQuery(querySql,
                    param.get("ysly"),
                    param.get("requestId"));
            rst.next();
            double syed = rst.getDouble("syed");
            if(syed<0){
                rst.rollback();
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            rst.rollback();
            return false;
        }
        rst.commit();
        return true;
    }
    //查询扣减金额  order by 来源类型  预算来源

    /**
     * requestId
     * bmjjzc
     *
     * @param param
     * @return
     */
    public RecordSet selectByReqIdAndBmjjzcAndOrderBy(Map<String,Object> param){
        RecordSet rs=new RecordSet();
        String sql="select * from uf_jingfeilaiyuan where requestId=? and bmjjzc=? order by lylx,ysly";
        rs.executeQuery(sql,
                param.get("requestId"),
                param.get("bmjjzc"));
        return rs;
    }
}
